package com.freewater.springboot.demo.aop.api.composite;

import org.jetbrains.annotations.NotNull;
import org.springframework.aop.support.StaticMethodMatcher;

import java.lang.reflect.Method;

public class MethodMatchers {

    public static class AddMethodMatcher extends StaticMethodMatcher {
        @Override
        public boolean matches(Method method, @NotNull Class<?> targetClass) {
            String methodName = method.getName();
            return methodName.startsWith("add");
        }
    }

    public static class DeleteMethodMatcher extends StaticMethodMatcher {

        @Override
        public boolean matches(Method method, @NotNull Class<?> targetClass) {
            String name = method.getName();
            return name.contains("delete") || name.endsWith("Name");
        }
    }

    public static class FindMethodMatcher extends StaticMethodMatcher {

        @Override
        public boolean matches(Method method, @NotNull Class<?> targetClass) {
            return method.getName().contains("find");
        }
    }
}
